package cn.te.helloo;

public class W4 {

        public static void main(String[] args) {
            Runnable My=new My();
            for (int i = 0; i <4; i++) {
                new Thread(My).start();
            }

        }
    }
     class  My implements  Runnable{
        int tickets =100;
        @Override
        synchronized  public void run() {

            while (true){
                if(tickets>0){
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+" --- "+tickets--);
                }else{
                    break;
                }
            }
        }
    }